<template>
  <div>
    <h2 align="center">优惠券页面</h2>
    <input type="button" value="增加优惠券" @click="add">

    <table class="table table-bordered">
      <tr>
        <td>ID</td>
        <td>标题</td>
        <td>优惠券类型</td>
        <td>开始时间</td>
        <td>结束时间</td>
        <td>操作</td>
      </tr>
      <tr v-for="(item,index) in discountList">
        <td>{{ index + 1 }}</td>
        <td>{{ item.dTitle }}</td>
        <td>{{ item.dtName }}</td>
        <td>{{ item.dBeginTime }}</td>
        <td>{{ item.dEndTime }}</td>
        <td>
          <input type="button" value="下架">
        </td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import {reactive,toRefs,onMounted}  from 'vue'
import  axios from 'axios'
import { useRouter,useRoute} from 'vue-router'
import { useUserStore} from '../stores/user'


const route = useRoute();
const router = useRouter();
const userStore = useUserStore()


let data:any = reactive({
  discountList:[]
})

let {discountList} = toRefs(data)


onMounted(()=>{
  getDiscountList()
})

//增加

const add = ()=>{
  router.push("/addDiscount")
}

//获取优惠券列表

const getDiscountList = ()=>{
  axios({
    url:'/api/Test/GetDiscountList',
    method:'get'
  })
  .then(res=>{
    console.log(res);
    discountList.value = res.data.data
    
  })
  .catch(err=>{
    console.log(err);
    
  })
}

</script>

<style scoped>

</style>